﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebPartControls_DocumentListControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        var ds = from document in dc.Documents
                 orderby document.Time descending
                 select new
                 {
                     标识 = document.Document_id,
                     标题 = document.Title,
                     日期 = document.Time.Value.Month + "-" + document.Time.Value.Day
                 };
        NewsListGridView.DataSource = ds.Take(5);
        NewsListGridView.DataBind();

        int i = 0;
        foreach (var document in ds.Take(5))
        {
            string Title = Convert.ToString(document.标题);
            ((LinkButton)NewsListGridView.Rows[i].FindControl("News_Title")).Text = Title;
            if (++i >= 5) break;;
        }
        dc.Dispose();
    }
    public string SubString(string sString, int nLength)
    {
        if (sString.Length <= nLength)
        {
            return sString;
        }
        string sNewStr = sString.Substring(0, nLength);
        sNewStr = sNewStr + "...";
        return sNewStr;
    }
    protected void NewsListGridView_OnSelectedIndexChange(object sender, GridViewSelectEventArgs e)
    {
        Session.Add("Document_id", ((Label)NewsListGridView.Rows[e.NewSelectedIndex].FindControl("News_id")).Text);
      //  Response.Redirect("Document.aspx");
        Page.RegisterStartupScript("", "<script>window.open('Document2.aspx')</script>");
    }
}
